﻿using System;
using System.Data;
using System.Collections.Generic;
using Royalsoft.Common;
using NJL.Model;
using NJL.DALFactory;
using NJL.IDAL;
namespace NJL.BLL
{
    /// <summary>
    /// NJL_TEMP_ORDER
    /// </summary>
    public partial class NJL_TEMP_ORDER
    {
        private readonly INJL_TEMP_ORDER dal = DataAccess.CreateNJL_TEMP_ORDER();
        public NJL_TEMP_ORDER()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(NJL.Model.NJL_TEMP_ORDER model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NJL.Model.NJL_TEMP_ORDER model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NJL.Model.NJL_TEMP_ORDER GetModel(string ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public NJL.Model.NJL_TEMP_ORDER GetModelByCache(string ID)
        {

            string CacheKey = "NJL_TEMP_ORDERModel-" + ID;
            object objModel = Royalsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ID);
                    if (objModel != null)
                    {
                        int ModelCache = Royalsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Royalsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (NJL.Model.NJL_TEMP_ORDER)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NJL.Model.NJL_TEMP_ORDER> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NJL.Model.NJL_TEMP_ORDER> DataTableToList(DataTable dt)
        {
            List<NJL.Model.NJL_TEMP_ORDER> modelList = new List<NJL.Model.NJL_TEMP_ORDER>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NJL.Model.NJL_TEMP_ORDER model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new NJL.Model.NJL_TEMP_ORDER();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = dt.Rows[n]["ID"].ToString();
                    }
                    if (dt.Rows[n]["NJL_SYS_BASE_ID"] != null && dt.Rows[n]["NJL_SYS_BASE_ID"].ToString() != "")
                    {
                        model.NJL_SYS_BASE_ID = dt.Rows[n]["NJL_SYS_BASE_ID"].ToString();
                    }
                    if (dt.Rows[n]["ORDER_NO"] != null && dt.Rows[n]["ORDER_NO"].ToString() != "")
                    {
                        model.ORDER_NO = dt.Rows[n]["ORDER_NO"].ToString();
                    }
                    if (dt.Rows[n]["BOOK_NAME"] != null && dt.Rows[n]["BOOK_NAME"].ToString() != "")
                    {
                        model.BOOK_NAME = dt.Rows[n]["BOOK_NAME"].ToString();
                    }
                    if (dt.Rows[n]["BOOK_MOBILE"] != null && dt.Rows[n]["BOOK_MOBILE"].ToString() != "")
                    {
                        model.BOOK_MOBILE = dt.Rows[n]["BOOK_MOBILE"].ToString();
                    }
                    if (dt.Rows[n]["ORDER_TOTAL"] != null && dt.Rows[n]["ORDER_TOTAL"].ToString() != "")
                    {
                        model.ORDER_TOTAL = decimal.Parse(dt.Rows[n]["ORDER_TOTAL"].ToString());
                    }
                    if (dt.Rows[n]["PAY_USE"] != null && dt.Rows[n]["PAY_USE"].ToString() != "")
                    {
                        model.PAY_USE = dt.Rows[n]["PAY_USE"].ToString();
                    }
                    if (dt.Rows[n]["ORDER_STATE"] != null && dt.Rows[n]["ORDER_STATE"].ToString() != "")
                    {
                        model.ORDER_STATE = int.Parse(dt.Rows[n]["ORDER_STATE"].ToString());
                    }
                    if (dt.Rows[n]["PAY_MAP_TYPE_CODE"] != null && dt.Rows[n]["PAY_MAP_TYPE_CODE"].ToString() != "")
                    {
                        model.PAY_MAP_TYPE_CODE = dt.Rows[n]["PAY_MAP_TYPE_CODE"].ToString();
                    }
                    if (dt.Rows[n]["CREATE_USER_NAME"] != null && dt.Rows[n]["CREATE_USER_NAME"].ToString() != "")
                    {
                        model.CREATE_USER_NAME = dt.Rows[n]["CREATE_USER_NAME"].ToString();
                    }
                    if (dt.Rows[n]["CREATE_USER_ID"] != null && dt.Rows[n]["CREATE_USER_ID"].ToString() != "")
                    {
                        model.CREATE_USER_ID = dt.Rows[n]["CREATE_USER_ID"].ToString();
                    }
                    if (dt.Rows[n]["CREATE_DATE_TIME"] != null && dt.Rows[n]["CREATE_DATE_TIME"].ToString() != "")
                    {
                        model.CREATE_DATE_TIME = DateTime.Parse(dt.Rows[n]["CREATE_DATE_TIME"].ToString());
                    }
                    if (dt.Rows[n]["PAY_DATE_TIME"] != null && dt.Rows[n]["PAY_DATE_TIME"].ToString() != "")
                    {
                        model.PAY_DATE_TIME = DateTime.Parse(dt.Rows[n]["PAY_DATE_TIME"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
        /// <summary>
        /// 根据订单编号查询订单信息
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public NJL.Model.NJL_TEMP_ORDER GetModelbyOrderId(string orderId)
        {
            NJL.Model.NJL_TEMP_ORDER model = new Model.NJL_TEMP_ORDER();
            DataSet ds = GetList("ORDER_NO='" + orderId + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                model = GetModel(ds.Tables[0].Rows[0][0].ToString());
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 查询用户编号和支付渠道
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListInPayMap(string strWhere)
        {
            return dal.GetListInPayMap(strWhere);
        }
    }
}

